
Imports System
Imports System.Data.SqlClient

Namespace _2bMatesSite.BO
	''' <summary>
	''' Represents a static list of the user's potential direct friends (invitations - pending/rejected).
	''' </summary>
	Public Class UserInvitations
		Inherits UsersFriends
		Private userIsInviter As Boolean
		Private onlyPending As Boolean

		Public Sub New(ByVal userID As Integer, ByVal userIsInviter As Boolean)
			MyBase.New(userID)
			Me.userIsInviter = userIsInviter
			onlyPending = False
		End Sub

		Public Sub New(ByVal userID As Integer, ByVal userIsInviter As Boolean, ByVal onlyPending As Boolean)
			MyBase.New(userID)
			Me.userIsInviter = userIsInviter
			Me.onlyPending = onlyPending
		End Sub

		Protected Overloads Overrides Function GetCommand(ByVal conn As SqlConnection) As SqlCommand
			Dim cmd As SqlCommand = Nothing

			Dim statusSQL As String = Nothing
			If onlyPending Then
				statusSQL = "Status = 0"
			Else
				statusSQL = "Status != 1"
			End If

			If userIsInviter Then
				cmd = New SqlCommand("SELECT * FROM DirectFriends WHERE UID=@UID AND " + statusSQL + " ORDER BY Status ASC")
			Else
				cmd = New SqlCommand("SELECT * FROM DirectFriends WHERE FriendUID=@UID AND " + statusSQL + " ORDER BY Status ASC")
			End If

			cmd.Connection = conn
			cmd.Parameters.Add("@UID", userID)
			Return cmd
		End Function
	End Class
End Namespace






